package com.xnyzc.lhy.common.component.config.security;

import lombok.Data;
import lombok.ToString;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: huxuekuo
 * @Date: 2019-07-20 17:43
 * @Description:
 */

@Configuration
@ToString
@Data
public class RocketConfig {


    @Value("${global.pang.mq.groupNames.consumerPre}")
    private String consumerGroupName;
    @Value("${global.pang.mq.nameServerAddr}")
    private String nameServerAddr;
    @Value("${global.pang.mq.groupNames.producer}")
    private String ProducerGroupName;
    @Value("${global.pang.mq.topics}")
    private String topic;
    @Value("${global.pang.mq.tag}")
    private String tag;


    /**
     * 创建普通消息发送者实例
     *
     * @return
     * @throws MQClientException
     */
    @Bean
    public DefaultMQProducer defaultProducer() throws MQClientException {
        DefaultMQProducer producer = new DefaultMQProducer(ProducerGroupName);
        producer.setNamesrvAddr(nameServerAddr);
        producer.setClientIP(nameServerAddr);
        producer.setInstanceName(ProducerGroupName);
        producer.setVipChannelEnabled(false);
        producer.setRetryTimesWhenSendAsyncFailed(10);
        producer.start();
        return producer;
    }
    RocketConfig(){
        System.setProperty("rocketmq.client.log.loadconfig","false");
    }
}
